//
// Created by 123 on 2025/1/13.
//
#include "iostream"
#include "vector"
#include "algorithm"

class MyPrint{
public:
    void operator()(int val){
        std::cout << val << " ";
    }
};

void test(){
    std::vector<int> v;
    for (int i = 0; i < 10; ++i) {
        v.push_back(i)  ;
    }
    std::vector<int> v2;
    v2.resize(v.size());
    std::copy(v.begin(),v.end(),v2.begin());
    std::for_each(v2.begin(),v2.end(),MyPrint());
    std::cout << std::endl;
}
void test2(){
    std::vector<int> v;
    for (int i = 0; i < 10; ++i) {
        v.push_back(i)  ;
    }
    std::replace(v.begin(),v.end(),3,19);
    std::for_each(v.begin(),v.end(),MyPrint());
    std::cout << std::endl;
}

class ReplaceGreate30{
public:
    bool operator()(int val){
        return val>30;
    }
};

bool com30(int val){
    return val>30;
}

void test3(){
    std::vector<int> v;
    v.push_back(10);
    v.push_back(30);
    v.push_back(66);
    v.push_back(50);
    v.push_back(40);
    //替换前
    std::for_each(v.begin(), v.end(),MyPrint());
    std::cout << std::endl;
    //替换后
//    std::replace_if(v.begin(), v.end(),ReplaceGreate30(),3000);
    std::replace_if(v.begin(), v.end(),com30,3000);
    std::for_each(v.begin(), v.end(),MyPrint());
    std::cout << std::endl;
}

int main160(){
    test();
    test2();
    test3();
    return 0;
}